package com.elitedatai.mchtest.media.repository;

import com.elitedatai.mchtest.media.model.MediaFileEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Arrays;
import java.util.List;


public interface MediaFileRepository extends JpaRepository<MediaFileEntity, Long> {
    MediaFileEntity findByWorkspaceIdAndFingerprint(String workspaceId, String fingerprint);

    MediaFileEntity findByWorkspaceIdAndFileId(String workspaceId, String fileId);

    List<MediaFileEntity> findByWorkspaceId(String workspaceId);

    @Query("SELECT m FROM MediaFileEntity m WHERE m.workspaceId = :workspaceId ORDER BY m.id DESC")
    Page<MediaFileEntity> findByWorkspaceIdOrderByDesc(@Param("workspaceId") String workspaceId, Pageable pageable);

    @Query("SELECT m FROM MediaFileEntity m WHERE m.workspaceId = :workspaceId AND m.jobId = :jobId")
    List<MediaFileEntity> findByWorkspaceIdAndJobId(@Param("workspaceId") String workspaceId,
                                                    @Param("jobId") String jobId);

}
